<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form Validator</title>

<script>

	function validateForm()
	{
		var $userName = document.forms["demo"]["name"].value;
		var $password = document.forms["demo"]["password"].value;
		var $EmailID = document.forms["demo"]["email"].value;
		
		validateName($userName);
		validatePassword($password);
		validateEmail($EmailID);
	}
	
	function validateEmail($EmailID)
	{
		var $atIndex = $EmailID.indexOf('@');
		var $dotIndex = $EmailID.lastIndexOf('.');
		alert($atIndex);
		alert($dotIndex);
		if(!($atIndex>0 && $dotIndex>0 && $atIndex < $dotIndex ))
		{
			alert("Invalid emailId");
		}
	}
	
	function validatePassword($password)
	{
		if ($password.length >= 10)
		{
			alert("too large password, only ten char allowed");
		}
	}
	
	function validateName($userName)
	{
		for ($index = 0; $index < $userName.length ; $index=$index+1)
		{
			if($userName[$index] >= 0 && $userName[$index] <= 9 )
			{
				alert("number found in name");
				break;
			}
		}
	}
	
</script>

</head>

<body>
	<form action="" method="get" onsubmit="return validateForm()" name="demo">
    	<table>
        	<tr>
            	<td>Name:</td> <td><input type="text" name="name" id="name" /></td>
            </tr>
            <tr>
            	<td>Password:</td> <td><input type="password" name="password" id="password" /></td>
            </tr>
			<tr>
            	<td>Email:</td> <td><input type="text" name="email" id="email" /></td>
            </tr>
        </table>
        <input type="submit" value="submit" />
    </form>	
</body>

</html>
